<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="head-title">
        <title>Add Raw Material Supplier | Merlion's ERP System</title>
    </ui:define>
    
    <ui:define name="content">
        <f:view >

            <p:panel id="panel" header="Add New Supplier"> 
                <p:ajaxStatus style="width:16px;height:16px;">   
                    <f:facet name="start">   
                        <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                    </f:facet> 
 
                    <f:facet name="complete">   
                        <h:outputText value="" />   
                    </f:facet>   
                </p:ajaxStatus>
                
                <p:messages/>
                
                <h:form prependId="false">
                    <p:fieldset legend="Supplier Detailes" style="font-weight: bold">
                        <h:panelGrid columns="3" cellpadding="4" >
                            <h:outputLabel for="supplierName" style="font-weight: bold" value="Supplier Name: "/>
                            <p:inputText value="#{addSupplier.supplierName}" required="true" label="Supplier Name" requiredMessage="Supplier Name is required." 
                                         validator="#{addSupplier.validateUniqueUser}" id="supplierName"/>
                            <p:message for="supplierName" id ="name"/>

                            <h:outputLabel for="supplierAddress" style="font-weight: bold" value="Supplier Address: "/>
                            <p:inputText value="#{addSupplier.supplierAddress}" required="true" label="Supplier Address" requiredMessage="Supplier Address is required." 
                                          id="supplierAddress"/>
                            <p:message for="supplierAddress" id="address"/>

                            <h:outputLabel for="supplierPostcode" style="font-weight: bold" value="Supplier Postcode: "/>
                            <p:inputText value="#{addSupplier.supplierPostcode}" required="true" label="Supplier Postcode" requiredMessage="Supplier Postcode is required."
                                         validator="#{addSupplier.validatePostCode}" id="supplierPostcode"/>
                            <p:message for="supplierPostcode" id="postcode"/>  

                            <h:outputLabel for="supplierContactNo" style="font-weight: bold" value="Supplier Contact Number: "/>
                            <p:inputText value="#{addSupplier.supplierContactNo}" required="true" label="Supplier Contact Number" requiredMessage="Supplier Contact Number is required." 
                                         validator="#{addSupplier.validateContactNumber}" id="supplierContactNo"/>
                            <p:message for="supplierContactNo" id="contactNo"/>                

                            <h:outputLabel for="supplierEmail" style="font-weight: bold" value="Supplier Email: "/>
                            <p:inputText value="#{addSupplier.supplierEmail}" required="true" label="Supplier Email" requiredMessage="Supplier Email is required." 
                                         validator="#{addSupplier.validateEmail}" id="supplierEmail"/>
                            <p:message for="supplierEmail" id="email"/>                
                        </h:panelGrid>

                        <p:dataTable value="#{addSupplier.supplyItemList}" var="supplyItem" id="supplyItemTable">
                            <p:column sortBy="#{supplyItem.supplyItemType}"> 
                                <f:facet name="header"> 
                                    <h:outputText value="Supply Item Type" /> 
                                </f:facet> 
                                <h:outputText value="#{supplyItem.supplyItemType}" /> 
                            </p:column>

                            <p:column sortBy="#{supplyItem.supplyItemPrice}"> 
                                <f:facet name="header"> 
                                    <h:outputText value="Price" /> 
                                </f:facet> 
                                <h:outputText value="#{supplyItem.supplyItemPrice}" /> 
                            </p:column>
                        </p:dataTable>
                        
                        <p:commandButton value="Add Supply Item" onclick="addSupplyItemDialog.show()" update="address email postcode contactNo name" ajax="true"/>
                        <p:commandButton id="btn" value="Save Supplier" update="panel" actionListener="#{addSupplier.saveSupplier(event)}" ajax="true" />
                       
                    </p:fieldset> 
                    
                    <p:dialog header="Add New Supply Item" widgetVar="addSupplyItemDialog" width="400" height="400" resizable="true" showEffect="clip" hideEffect="fold">
                        <h:panelGrid id="display" columns="2">
                            <h:outputText value="Supply Item Type:"/>
                            <h:selectOneMenu id="supplyItemType" value="#{addSupplier.newSi.supplyItemType}">
                                <f:selectItem itemLabel="Select Raw Material Type " itemValue="" />
                                <f:selectItems value="#{addSupplier.materials}"/>
                            </h:selectOneMenu>  
                            <h:outputText value="Supply Item Price:"/>
                            <h:inputText value="#{addSupplier.newSi.supplyItemPrice}" required="true"/>
                            <p:commandButton value="Add" actionListener="#{addSupplier.addSupplyItem(event)}" update="supplyItemTable" oncomplete="addSupplyItemDialog.hide()"/>  
                        </h:panelGrid>
                    </p:dialog>                
               </h:form>
                
            </p:panel>
        </f:view>
    </ui:define>

</ui:composition>
